/**
 * 
 */
package cw.serviceImp;

import java.util.List;
import java.util.Random;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cw.entity.Competition;
import cw.mapper.ArrangeGroupMapper;
import cw.mapper.CompetitionMapper;
import cw.service.CompetitionService;

/**
 * @author Administrator
 *
 */
@Service("CompetitionService")
public class CompetitionServiceImpl implements CompetitionService {

	
	
	@Resource
	private CompetitionMapper competitionMapper;

	
	/* (non-Javadoc)
	 * @see cw.service.CompetitionService#deleteByPrimaryKey(java.lang.Integer)
	 */
	@Override
	public int deleteByPrimaryKey(Integer id) {
		// TODO Auto-generated method stub
		return competitionMapper.deleteByPrimaryKey(id);
	}

	/* (non-Javadoc)
	 * @see cw.service.CompetitionService#insert(cw.entity.Competition)
	 */
	@Override
	public int insert(Competition record) {
		// TODO Auto-generated method stub
		return competitionMapper.insert(record);
	}

	/* (non-Javadoc)
	 * @see cw.service.CompetitionService#insertSelective(cw.entity.Competition)
	 */
	@Override
	public int insertSelective(Competition record) {
		// TODO Auto-generated method stub
		return competitionMapper.insertSelective(record);
	}

	/* (non-Javadoc)
	 * @see cw.service.CompetitionService#selectByPrimaryKey(java.lang.Integer)
	 */
	@Override
	public Competition selectByPrimaryKey(Integer id) {
		// TODO Auto-generated method stub
		return competitionMapper.selectByPrimaryKey(id);
	}

	/* (non-Javadoc)
	 * @see cw.service.CompetitionService#updateByPrimaryKeySelective(cw.entity.Competition)
	 */
	@Override
	public int updateByPrimaryKeySelective(Competition record) {
		// TODO Auto-generated method stub
		return competitionMapper.updateByPrimaryKeySelective(record);
	}

	/* (non-Javadoc)
	 * @see cw.service.CompetitionService#updateByPrimaryKey(cw.entity.Competition)
	 */
	@Override
	public int updateByPrimaryKey(Competition record) {
		// TODO Auto-generated method stub
		return competitionMapper.updateByPrimaryKey(record);
	}

	/* (non-Javadoc)
	 * @see cw.service.CompetitionService#queryCompetition(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.Integer, java.lang.Integer)
	 */
	@Override
	public List<Competition> queryCompetition(String teamId, String teamTid,
			String description, String id, Integer offset, Integer pageSize) {
		// TODO Auto-generated method stub
		return competitionMapper.queryCompetition(teamId, teamTid, description, id, offset, pageSize);
	}

	/* (non-Javadoc)
	 * @see cw.service.CompetitionService#getTotal(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
	 */
	@Override
	public Integer getTotal(String teamId, String teamTid, String description,
			String id) {
		// TODO Auto-generated method stub
		return competitionMapper.getTotal(teamId, teamTid, description, id);
	}

	/* (non-Javadoc)
	 * @see cw.service.CompetitionService#query()
	 */
	@Override
	public List<Competition> query() {
		// TODO Auto-generated method stub
		return competitionMapper.query();
	}

	@Override
	public int deleteAll() {
		// TODO Auto-generated method stub
		return competitionMapper.deleteAll();
	}

	@Override
	public void arrangeCompetition(List<Integer> list) {
		// TODO Auto-generated method stub
		//组内循环赛
		    Integer teamId = list.get(0);
			list.remove(teamId);
			if(list.size()>0 &&list!=null){
				for(int i=0;i<list.size();i++){
					System.out.println("第"+i+"队："+teamId+"---"+list.get(i));
					//得到pk的比赛，将pk队存入数据库
				}
				System.out.println("------"+list.size());
				arrangeCompetition(list);
			}	
		
	}

	@Override
	public void arrangePkCompetition(List<Integer> list) {
		// TODO Auto-generated method stub
		//淘汰赛
		Random ran = new Random();
		Integer teamId = list.get(0);
		list.remove(teamId);
		if(list.size()>0 && list!=null){
			Integer teamTid = list.get(ran.nextInt(list.size()));
			System.out.println("第"+"队："+teamId+"---"+teamTid);
			list.remove(teamTid);
			System.out.println();
			arrangePkCompetition(list);
		}
	}

}
